<script>
import outMain from "@/components/outMain.vue";
import upMoreImg from "@/components/public/upMoreImg.vue";
import tableBigImg from "@/components/public/tableBigImg.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { cyxz, cyxzSave, jsVoucher } from "@/http/api";
export default {
  components: { outMain, upMoreImg, tableBigImg },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "未结算", value: "1" },
        { label: "已结算", value: "3" },
      ],
      monthArr: [
        { label: "全部", value: "" },
        { label: "本月", value: "1" },
        { label: "近三个月", value: "2" },
        { label: "近半年", value: "3" },
        { label: "近一年", value: "4" },
      ],
      queryData: {
        js_order_number: "",
        real_name: "",
        js_status: "",
        jsxz_time: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
      upRow: {},
      showUpRow: false,
      upImgFiles: "",
    };
  },
  props: {},
  setup() {},
  methods: {
    upImg(row) {
      this.upRow = row;
      this.showUpRow = true;
      this.upImgFiles = "";
    },
    getImg(url) {
      this.upImgFiles = url;
    },
    saveUpImg() {
      if (!this.upImgFiles) {
        ElMessage({
          type: "error",
          message: "请上传结算的凭证图片",
        });
        return false;
      }
      let data = {
        shipowner_manage_money_id: this.upRow.shipowner_manage_money_id,
        jsxz_img: this.upImgFiles,
      };
      jsVoucher(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
          this.showUpRow = false;
        }
      });
    },
    subFn(row) {
      ElMessageBox.confirm(
        `确定为船员${row.real_name}办理${row.content}的薪酬结算吗?`,
        "操作提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        let data = {
          shipowner_manage_money_id: row.shipowner_manage_money_id,
        };
        cyxzSave(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    detailFn(id) {
      this.$router.push({
        path: "/bootMoneyDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    async getData() {
      const { data } = await cyxz(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>船员薪酬结算记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.js_order_number"
                placeholder="请输入结算单号"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.real_name"
                placeholder="请输入船员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.js_status"
                clearable
                @change="getData"
                placeholder="请选择结算状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.jsxz_time"
                clearable
                @change="getData"
                placeholder="请选择结算时间"
              >
                <el-option
                  v-for="item in monthArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="js_order_number"
          width="150"
          show-overflow-tooltip
          label="结算单号"
        />
        <el-table-column
          prop="real_name"
          show-overflow-tooltip
          label="船员姓名"
        >
          <template #default="{ row }">
            {{ row.real_name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="content"
          show-overflow-tooltip
          label="结算月份"
        />
        <el-table-column show-overflow-tooltip label="薪资金额">
          <template #default="{ row }">
            {{ row.xz_money_dw == 1 ? "¥" : "$" }}{{ row.xz_money }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="社保金额">
          <template #default="{ row }">
            {{ row.sb_money_dw == 1 ? "¥" : "$" }}{{ row.sb_money }}
          </template>
        </el-table-column>
        <el-table-column prop="Name" show-overflow-tooltip label="结算状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag type="infp" v-if="row.js_status == 1">待结算</el-tag>
              <el-tag type="success" v-if="row.js_status == 3">已结算</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="jsxz_time"
          width="180"
          show-overflow-tooltip
          label="结算时间"
        />
        <el-table-column prop="jsxz_img" label="结算凭证">
          <template #default="{ row }"
            ><tableBigImg
              v-if="row.jsxz_img"
              :propImg="row.jsxz_img.split(',')"
              :src="row.jsxz_img.split(',')[0]"
            ></tableBigImg
          ></template>
        </el-table-column>
        <el-table-column
          prop="jsxz_staff_name"
          show-overflow-tooltip
          label="操作员工"
        >
          <template #default="{ row }">
            {{ row.jsxz_staff_name }}
          </template>
        </el-table-column>
        <el-table-column prop="Name" width="160" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.shipowner_manage_money_id)"
              >
                详情
              </div>
              <div
                class="blueText ctrlText"
                v-if="
                  (row.js_status == 1 || row.js_status == 4) && row.is_auth == 1
                "
                @click="subFn(row)"
              >
                结算
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.is_auth == 1 && row.js_status == 3"
                @click="upImg(row)"
              >
                上传凭证
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
      <el-dialog
        v-model="showUpRow"
        title="结算凭证"
        width="500"
        :close-on-click-modal="false"
      >
        <div>
          <upMoreImg @ok="getImg"></upMoreImg>
        </div>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="showUpRow = false">取消</el-button>
            <el-button type="primary" @click="saveUpImg"> 确认 </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
